<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
        <li>abcd</li>
    </ul>
    <script>
        let lis = document.getElementsByTagName('li')
        for (let i = 0; i < lis.length; i++) {
            i % 2 ? lis[i].style.backgroundColor = 'red' : lis[i].style.backgroundColor = 'blue'
            let currentColor = ''
            lis[i].onmouseover = () => {
                currentColor = lis[i].style.backgroundColor
                lis[i].style.background = 'green'

            }
            lis[i].onmouseout = () => {
                lis[i].style.backgroundColor = currentColor
            }
        }
    </script>
</body>

</html>